using System.Data;
using NUnit.Framework;
using NUnitAddinAttributes;

namespace SDG.UnitTesting.SimpleTalk.Tests
{
    [TestFixture]
    public class DataAccessTestsV2
    {
        [TestFixtureSetUp]
        public void TestFixtureSetup()
        {
            SDGConsoleWrapper sdgConsoleWrapper = new SDGConsoleWrapper(@"Database\NorthwindEmployees_Orders.sqlgen");
            sdgConsoleWrapper.Execute();
        }

        [Test]
        public void GetAllEmployees_SDGProject_1000Rows()
        {
            DataTable dt = DataAccess.GetAllEmployees();
            Assert.AreEqual(1000, dt.Rows.Count);
        }

        [Test]
        public void GetEmployeeByID_SDGProject_1RowReturned()
        {
            DataTable dt = DataAccess.GetEmployeeByID(1);
            Assert.AreEqual(1, dt.Rows.Count);
        }
    }

    [TestFixture]
    public class DataAccessV2_WithoutSDG
    {
        [Test]
        [ExecuteSql(ExecuteWhen = TestSequence.Before,  //Taken from Testing Times Ahead: Extending NUnit
                    Script = "DELETE FROM [Order Details];DELETE FROM Orders;DELETE FROM EmployeeTerritories;DELETE FROM Employees;",
                    Connection = "Server=(local);Database=Northwind;Integrated Security=True")]
        public void GetAllEmployees_EmptyDatabase_ZeroRows()
        {
            DataTable dt = DataAccess.GetAllEmployees();
            Assert.AreEqual(0, dt.Rows.Count);
        }
    }
}
